home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8206
/
8206.xpi
/
content
/
overlay.js
< prev
next >
Wrap
Text File
|
2010-02-02
|
9KB
|
252 lines
var WisestampOverlay =
{
app: null,
_prefs: null,
get prefs() {
if (!this._prefs) {
this._prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
this._prefs = this._prefs.getBranch("extensions.wisestamp.");
}
return this._prefs;
},
onLoad: function ()
{
// initialization code
this.initialized = true;
this.setSignatureType();
this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefs.addObserver("", this, false);
this.app = WisestampGetAppObject();
this.app.onLoad();
this.updateEnabledState();
this.updateStatusbarState();
this.checkVersionUpdate();
WiseStampUtils.log("[overlay.js::onLoad] Version = "+WiseStampUtils.getVersion()+", app = "+WiseStampUtils.getAppType()+" ver. "+WiseStampUtils.getAppVersion());
WiseStampComm.writeLog(WiseStampComm.LOG_EVENT_INIT,
WiseStampUtils.getVersion(), WiseStampUtils.getAppType(), WiseStampUtils.getAppVersion(),
WiseStampPrefs.getBoolPref("promote"));
function wisestampWebListener(e) {
alert("data:" + e.target.getAttribute("signatureContent"));
}
document.addEventListener("WisestampExtensionEvent", wisestampWebListener, false, true);
},
onUnload: function () {
this.initialized = false;
this.prefs.removeObserver("", this);
document.removeEventListener("ShowWisestampMenu", this, false, true);
var context = document.getElementById("contentAreaContextMenu");
if (context) context.removeEventListener("popupshowing", this, false);
},
checkVersionUpdate: function () {
var currentVersion = WiseStampUtils.getVersion();
var lastVersion = this.prefs.getCharPref("currentVersion");
if (lastVersion == "none") {
this.prefs.setCharPref("currentVersion", currentVersion);
//var firstrunURL = "http://www.wisestamp.com/first-steps".replace("{previous}","").replace("{current}",currentVersion);
var firstrunURL = "http://www.wisestamp.com/first-steps";
window.setTimeout(function () {
WisestampOverlay.app.openFirstRun();
},
3000);
} else if (lastVersion != currentVersion) {
this.prefs.setCharPref("currentVersion", currentVersion);
/* any upgrade code goes here */
window.setTimeout(function () {
WisestampOverlay.app.openUpdate(currentVersion);
},
3000);
}
},
setSignatureType: function (aType, aChangePref, popup) {
var current = this.prefs.getCharPref("type");
if (!aType) aType = current;
this.onPopupShowing(null, popup);
if (aChangePref && current != aType) {
this.prefs.setCharPref("type", aType);
}
},
onMenuItemCommand: function (event) {
this.onEditSignature(event);
},
onUseSignature: function (event, aType, aPopup) {
WiseStampUtils.log("[overlay.js::onUseSignature] >>>>> ");
this.setSignatureType(aType, false, aPopup);
this.app.onUseSignature(event, aType);
},
onEditSignature: function (event) {
/* Open options window */
var optionsURL = "chrome://wisestamp/content/options.xul";
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var windows = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getEnumerator(null);
while (windows.hasMoreElements()) {
var win = windows.getNext();
if (win.document.documentURI == optionsURL) {
win.focus();
return;
}
}
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
var features;
try {
var instantApply = prefs.getBoolPref("browser.preferences.instantApply");
instantApply = true;
features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
} catch(e) {
features = "chrome,titlebar,toolbar,centerscreen,modal";
}
openDialog(optionsURL, "", features);
},
onStatusClicked: function (event) {
if (event.button == 0) {
//this.toggleState();
}
},
toggleState: function () {
this.prefs.setBoolPref("enabled", !this.enabled);
},
onPopupShowing: function (event, popup) {
if (!document.getElementById("wisestampStatusPopup"))
return false;
if (typeof WisestampCompose != "undefined")
{
if (!this.prefs.getBoolPref("enabled"))
return false;
}
var current = event ? WisestampSignatureFactory.lastInserted : null;
if (!current)
current = this.prefs.getCharPref("type");
if (!popup)
popup = "";
if (popup == "") {
var enableItem = document.getElementById("wisestamp-enable");
var disableItem = document.getElementById("wisestamp-disable");
var target = document.popupNode;
if (target && target.id == "wisestamp-statusbar")
disableItem.hidden = !(enableItem.hidden = this.enabled);
else
disableItem.hidden = enableItem.hidden = true;
}
var signatures = WiseStampUtils.getSignaturesFromPref();
var container, menuseparator;
if (popup == "-menu") {
container = document.getElementById("context-wisestamp").firstChild;
menuseparator = document.getElementById("wisestamp_context_separator");
} else if (popup == "") {
container = document.getElementById("wisestampStatusPopup");
menuseparator = document.getElementById("wisestamp_popup_separator");
}
if (menuseparator)
{
/* clear out existing entries */
while (container.firstChild.id != menuseparator.id) {
container.removeChild(container.firstChild);
}
function buildSigPopupMenuitem(label, sig)
{
sig = sig ? sig : encodeURIComponent(label.replace(/^\s+|\s+$/, "").toLowerCase());
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("id", "wisestamp" + popup + "-type-" + sig);
menuitem.setAttribute("label", label);
menuitem.setAttribute("value", sig);
menuitem.setAttribute("type", "checkbox");
if (current == sig || ((current == "" || !current) && sig == "none"))
menuitem.setAttribute("checked", "true");
var objname = typeof WisestampCompose != "undefined" ? "WisestampCompose" : "WisestampOverlay";
menuitem.setAttribute("oncommand", objname + ".onUseSignature(event, '" + sig + "', '" + popup + "');")
return menuitem;
}
for each(var label in signatures) {
var menuitem = buildSigPopupMenuitem(label);
container.insertBefore(menuitem, menuseparator);
}
if (popup == "") {
var menuitem = buildSigPopupMenuitem("None", "none");
container.insertBefore(menuitem, menuseparator);
}
}
return true;
},
updateEnabledState: function () {
this.enabled = this.prefs.getBoolPref("enabled");
var statusbar = document.getElementById("wisestamp-statusbar");
if (statusbar) {
statusbar.setAttribute("state", this.enabled ? "enabled" : "disabled");
}
if (this.enabled) {
this.app.enable();
} else this.app.disable();
},
updateStatusbarState: function () {
var statusbar = document.getElementById("wisestamp-statusbar");
if (statusbar) {
var hidestatusbar = this.prefs.getBoolPref("hidestatusbar");
statusbar.hidden = hidestatusbar;
}
},
hideToolbarButton: function () {
//dump("val: "+this.prefs.getBoolPref("hidebuttons")+"\n");
var hide = this.prefs.getBoolPref("hidebuttons");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var enumerator = wm.getEnumerator(null);
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
if (win.location.toString() == "chrome://messenger/content/messengercompose/messengercompose.xul") {
//dump("uri: "+win.location+"\n");
var bttn = win.document.getElementById("wisestampButton");
bttn.setAttribute("hidden", hide);
}
// win is [Object ChromeWindow] (just like window), do something with it
}
},
observe: function (subject, topic, data)
{
if (topic != "nsPref:changed")
return;
switch (data)
{
case "enabled":
this.updateEnabledState();
break;
case "hidestatusbar":
this.updateStatusbarState();
break;
case "hidebuttons":
this.hideToolbarButton();
break;
}
}
};
window.addEventListener("load", function (e) { WisestampOverlay.onLoad(e); }, false);
window.addEventListener("unload", function (e) { WisestampOverlay.onUnload(e); }, false);